package com.stary.springmvc.web.dataValid.entity;

import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;

import javax.validation.constraints.NotNull;
import javax.xml.crypto.Data;
import java.util.Date;

/**
 * @author: Guan
 **/
public class Monster {
    private Integer id;
    //Asserts that the annotated string, collection, map or array is not {@code null} or empty.
    //注意NotEmpty注解修饰类型有限、
    //表示注解修饰属性（字段）不能为空且size不为0（null和空）
    //@NotEmpty有属性message，作用同i18n.properties的作用（自定义验证错误信息）
    @NotEmpty
    private String email;
    //注解控制范围，表示接收到的值要在1到100之间
    @Range(min = 1,max = 100)
    @NotNull(message = "年龄不能为空")
    private Integer age;


    //注解表示name
    // @NotEmpty
    //演示取消属性绑定，拿掉验证注解
    // private String name = "XXX";
    private String name;
    // @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "生日不能为空")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    // @NumberFormat(pattern = "###,###.##")
    @NotNull(message = "薪水不能为空")
    @NumberFormat(pattern = "###,###.##")
    //补充：格式要求没那么高，只要能转换成数字即可
    private Float salary;

    public Monster() {
    }

    public Monster(Integer id, String email, Integer age, String name, Date birthday, Float salary) {
        this.id = id;
        this.email = email;
        this.age = age;
        this.name = name;
        this.birthday = birthday;
        this.salary = salary;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getAge() {
        return age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Float getSalary() {
        return salary;
    }

    public void setSalary(Float salary) {
        this.salary = salary;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Monster{" +
                "id=" + id +
                ", email='" + email + '\'' +
                ", age=" + age +
                ", name='" + name + '\'' +
                ", birthday=" + birthday +
                ", salary=" + salary +
                '}';
    }
}
